{% load i18n %}
{% load dv_filters %}
<thead>
  {% with can_crud=user|can:'challenge_season_crud' %}
    <tr>
        <td rowspan="{% if chosen_stats %}6{% else %}5{% endif %}" colspan="{{ preamble_columns|default:3 }}">&nbsp;</td>
        {% if chosen_stats or sel_column %}<td rowspan="6">{% trans "Sél." %}</td>{% endif %}
        {% if wishfield %}<td rowspan="6">{% trans "Qualifs max" %}</td>{% endif %}
        {% for session in sessions %}
            <th data-test="orga-{{ session.pk }}" data-filter-orga="{{ session.orga.pk }}" class="text-center" style="vertical-align: top;">
                {% if session.orga.abbr %}{{ session.orga.abbr_verb }}{% else %}{{ session.orga.name }}{% endif %}
            </th>
        {% endfor %}</tr>
    <tr>{% for session in sessions %}
            <th class="text-center">{% if session.address_city %}{{ session.address_city }}{% elif session.orga.address_city %}{{ session.orga.address_city }}{% endif %}</th>
        {% endfor %}</tr>
    <tr>{% for session in sessions %}
            <th class="text-center">{{ session.day|date:"D" }} {{ session.day|date_ch_short }}</th>
        {% endfor %}</tr>
    <tr>{% for session in sessions %}
            <th class="text-center" style="font-weight: normal">{{ session.begin|date:"H\hi" }} {{ session.end|date:"H\hi" }}</th>
        {% endfor %}</tr>
    <tr>{% for session in sessions %}
            <th class="text-center">
            {% if can_crud or user|unprivileged_user_can_see:session.season and session.visible %}
              <a id="sess{{session.pk}}" href="{% url 'session-detail' seasonpk=session.season.pk pk=session.pk %}" title="{% trans "Vers la session" %}">
            {% endif %}
            {% blocktrans count n=session.n_qualifs|add:'0' %}1 Qualif’{% plural %}{{ n }} Qualifs{% endblocktrans %}
            {% if can_crud or user|unprivileged_user_can_see:session.season and session.visible %}
              </a>
            {% endif %}
            </th>
        {% endfor %}</tr>
    {% if chosen_stats %}
        <tr>{% for session in sessions %}
                <th style="text-align: center">
                    {# Be sure to adapt JS on season-staff-update if you change the html here #}
                    <dl class="small dl-horizontal">
                        {% with c=session.n_leaders %}
                            <dt>{% trans "M2" %}</dt>
                            <dd data-test-m2="{{ session.pk }}">
                                <span class="count-display {% if c >= session.helper_needs.2 %}hidden{% endif %}">{{ c }}/{{ session.helper_needs.2 }}</span>
                                <span class="glyphicon glyphicon-ok {% if c != session.helper_needs.2 %}hidden{% endif %}"
                                      title="{{ c }}/{{ session.helper_needs.2 }}"></span>
                                <span class="glyphicon glyphicon-alert {% if c <= session.helper_needs.2 %}hidden{% endif %}"
                                      title="{{ c }}/{{ session.helper_needs.2 }}"></span>
                            </dd>
                        {% endwith %}
                        {% with c=session.n_helpers %}
                            <dt>{% trans "M1" %}</dt>
                            <dd data-test-m1="{{ session.pk }}">
                                <span class="count-display {% if c >= session.helper_needs.1 %}hidden{% endif %}">{{ c }}/{{ session.helper_needs.1 }}</span>
                                <span class="glyphicon glyphicon-ok {% if c != session.helper_needs.1 %}hidden{% endif %}"
                                      title="{{ c }}/{{ session.helper_needs.1 }}"></span>
                                <span class="glyphicon glyphicon-alert {% if c <= session.helper_needs.1 %}hidden{% endif %}"
                                      title="{{ c }}/{{ session.helper_needs.1 }}"></span>
                            </dd>
                        {% endwith %}

                        {% with c=session.n_actors %}
                            <dt>{% trans "Int." %}</dt>
                            <dd data-test-int>
                                <span class="count-display {% if c >= session.actor_needs %}hidden{% endif %}">{{ c }}/{{ session.actor_needs }}</span>
                                <span class="glyphicon glyphicon-ok {% if c != session.actor_needs %}hidden{% endif %}"
                                      title="{{ c }}/{{ session.actor_needs }}"></span>
                                <span class="glyphicon glyphicon-alert {% if c <= session.actor_needs %}hidden{% endif %}"
                                      title="{{ c }}/{{ session.actor_needs }}"></span>
                            </dd>
                        {% endwith %}
                    </dl>
                </th>
            {% endfor %}</tr>
    {% endif %}
  {% endwith %}
</thead>
